home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume8 / gnuplot1.10A / part05 < prev    next >
Encoding:
Text File  |  1989-09-09  |  28.7 KB  |  1,205 lines

  1. Newsgroups: comp.sources.misc
  2. From: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  3. Subject: v08i039: GnuPlot v1.10A (part 5 of 7)
  4. Reply-To: canoaf@ntvax.UUCP (Augustine Cano)
  5.  
  6. Posting-number: Volume 8, Issue 39
  7. Submitted-by: canoaf@ntvax.UUCP (Augustine Cano)
  8. Archive-name: gnuplot1.10A/part05
  9.  
  10. [OOPS!!!  I had to patch these after receiving them -- and managed to lose the
  11. name of the person who submitted them in the process.  Duh.  The name shown
  12. is a "best guess".  Submitter, please correct me.  ++bsa]
  13.  
  14. #! /bin/sh
  15. # This is a shell archive.  Remove anything before this line, then unpack
  16. # it by saving it into a file and typing "sh file".  To overwrite existing
  17. # files, type "sh file -c".  You can also feed this as standard input via
  18. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  19. # will see the following message at the end:
  20. #        "End of archive 5 (of 7)."
  21. # Contents:  unixpc.trm unixplot.trm util.c v384.trm version.c
  22. # Wrapped by allbery@uunet on Sat Sep  9 13:47:23 1989
  23. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  24. if test -f 'unixpc.trm' -a "${1}" != "-c" ; then 
  25.   echo shar: Will not clobber existing file \"'unixpc.trm'\"
  26. else
  27. echo shar: Extracting \"'unixpc.trm'\" \(12181 characters\)
  28. sed "s/^X//" >'unixpc.trm' <<'END_OF_FILE'
  29. X/*
  30. XFrom: John Campbell (...!arizona!naucse!jdc)
  31. X
  32. XI ported gnuplot to the ATT 3b1 (ATT7300) on 12/4/88.  The 3b1, as I view
  33. Xit, is a 720x300 bitmapped, monochrome display (often people don't use
  34. Xthe top 12 scan lines and thus the effective size is 720x288).  I tried to
  35. Xmaximize the size of the graph area, by using these top 12 lines (normally
  36. Xreserved) and set up a signal handler to restore them upon exit, abort, etc.
  37. X
  38. XLine styles were "fudged" (they do not know the aspect ratio).  The same
  39. Xline style may look different depending upon the slope of the curve.  Due to
  40. Xthis only 4 line styles were implemented.  While more line types are possible,
  41. Xthe current styles were chosen as distinguishable.
  42. X
  43. XThe 3b1 has 4 "special" rows at the bottom that I could not use in graphics
  44. Xmode.  I chose to use these lines for the plot scale--normally found at the
  45. Xbottom right corner of the plot.  I wanted to use the four bottom lines as
  46. Xprompt/command lines, but did not find a way to do this.  If someone ever
  47. Xwrites a device driver to "open" these rows as a small separate window, I
  48. Xcould implement my original idea.
  49. X*/
  50. X
  51. X#include <sys/window.h>   /* Started with tam.h--too much trouble. */
  52. X#include <sys/signal.h>
  53. X#include <errno.h>
  54. X
  55. X#define uPC_HIGH_BIT    (0x8000)
  56. X
  57. Xtypedef unsigned short Scr_type;
  58. Xtypedef unsigned char Scr_kluge;
  59. X
  60. X#define uPC_XMAX 720
  61. X#define uPC_YMAX 300
  62. X
  63. X#define uPC_XSIZE       45 /* Short ints. */
  64. X#define uPC_YSIZE uPC_YMAX
  65. X
  66. XScr_type uPC_display[uPC_YSIZE][uPC_XSIZE];
  67. Xint uPC_width = 2*uPC_XSIZE;
  68. Xint uPC_sx=0, uPC_sy=0;
  69. Xint uPC_cur_linetype=0;
  70. Xunsigned short uPC_raster_count=0;
  71. X
  72. X#define uPC_XLAST (uPC_XMAX - 1)
  73. X#define uPC_YLAST (uPC_YMAX - 1)
  74. X
  75. X#define uPC_VCHAR 12
  76. X#define uPC_HCHAR  9
  77. X#define uPC_VTIC   8
  78. X#define uPC_HTIC  12
  79. X
  80. Xextern errno, sys_nerr;
  81. Xextern char *sys_errlist[];
  82. X
  83. Xstatic struct urdata uPC_ur = {(unsigned short *)uPC_display, 2*uPC_XSIZE, 0, 0,
  84. X                           0, 0, 0, 0, uPC_XMAX, uPC_YMAX, SRCSRC, DSTOR, 0};
  85. X
  86. X#define IfErrOut(e1,e2,s1,s2) if (e1 e2) {\
  87. Xfprintf(stderr, "%s:: %s %s\n", sys_errlist[errno], s1, s2);\
  88. XuPC_fixwind(0);\
  89. Xexit(-1);}
  90. X
  91. XuPC_init()
  92. X{
  93. X/* This routine will ioctl to change 0 size */
  94. X   int i;
  95. X   struct uwdata uw;
  96. X   int uPC_fixwind();
  97. X   short gw;
  98. X
  99. X/* Check that we are on the bitmapped window. */
  100. X   if (iswind() != 0) {
  101. X      fprintf (stderr, "Sorry--must run from the bitmapped terminal\n");
  102. X      exit(-1);
  103. X   }
  104. X   for (i=1; i<=16; i++) {
  105. X      if (i != SIGINT && i != SIGFPE)  /* Two are caught in plot.c */
  106. X         signal (i, uPC_fixwind);
  107. X   }
  108. X
  109. X/* Increase the screen size */
  110. X   uw.uw_x = 0;
  111. X   uw.uw_y = 0;   /* Leave room for top status line. */
  112. X   uw.uw_width = uPC_XMAX;      /* 720 */
  113. X   uw.uw_height = uPC_YMAX;     /* 288 normal--we clobber 12 (top row)*/
  114. X   uw.uw_uflags = 1;         /* Creates with no border */
  115. X
  116. X   IfErrOut (ioctl(0, WIOCSETD, &uw), <0, "ioctl failed on", "WIOCSETD");
  117. X}
  118. X
  119. X
  120. XuPC_graphics()
  121. X{
  122. X/* This routine will clear the uPC_display buffer and window. */
  123. X   register Scr_type *j;
  124. X   register int i;
  125. X
  126. X   j = (Scr_type *)uPC_display;
  127. X   i = uPC_YSIZE*uPC_XSIZE + 1;
  128. X
  129. X   while (--i)
  130. X      *j++ = 0;
  131. X
  132. X   uPC_ur.ur_dstop = DSTSRC;   /* replace (clear screen). */
  133. X   IfErrOut (ioctl(0, WIOCRASTOP, &uPC_ur), <0,
  134. X      "ioctl failed", "WIOCRASTOP");
  135. X   uPC_ur.ur_dstop = DSTOR;   /* Or in (show text) */
  136. X}
  137. X
  138. X
  139. XuPC_text()
  140. X{
  141. X/* This routine will flush the display. */
  142. X
  143. X   IfErrOut (ioctl(0, WIOCRASTOP, &uPC_ur), <0,
  144. X      "ioctl failed", "WIOCRASTOP");
  145. X/* Now position the cursor at the second to the last row--better later? */
  146. X   wgoto (0, 24, 0);
  147. X}
  148. X
  149. X
  150. XuPC_linetype(linetype)
  151. Xint linetype;
  152. X{
  153. X/* This routine records the current linetype. */
  154. X   if (uPC_cur_linetype != linetype) {
  155. X      uPC_raster_count = 0;
  156. X      uPC_cur_linetype = linetype;
  157. X   }
  158. X}
  159. X
  160. X
  161. XuPC_move(x,y)
  162. Xunsigned int x,y;
  163. X{
  164. X/* This routine just records x and y in uPC_sx, uPC_sy */
  165. X   uPC_sx = x;
  166. X   uPC_sy = y;
  167. X}
  168. X
  169. X
  170. X/* Was just (*(a)|=(b)) */
  171. X#define uPC_PLOT(a,b)   (uPC_cur_linetype != 0 ? uPC_plot_word (a,b) :\
  172. X                                *(a)|=(b))
  173. X
  174. XuPC_plot_word(a,b)
  175. XScr_type *a, b;
  176. X/*
  177. X   Weak attempt to make line styles.  The real problem is the aspect
  178. X   ratio.  This routine is called only when a bit is to be turned on in
  179. X   a horizontal word.  A better line style routine would know something
  180. X   about the slope of the line around the current point (in order to
  181. X   change weighting).
  182. X
  183. X   This yields 3 working linetypes plus a usable axis line type.
  184. X*/
  185. X{
  186. X/* Various line types */
  187. X   switch (uPC_cur_linetype) {
  188. X   case -1:
  189. X   /* Distinguish between horizontal and vertical axis. */
  190. X      if (uPC_sx > uPC_XMAX/8 && uPC_sx < 7*uPC_XMAX/8) {
  191. X      /* Fuzzy tolerance because we don't know exactly where the y axis is */
  192. X         if (++uPC_raster_count % 2 == 0) *(a) |= b;
  193. X      }
  194. X      else {
  195. X      /* Due to aspect ratio, take every other y pixel and every third x. */
  196. X         *(a) |= (b & 0x9999);
  197. X      }
  198. X   break;
  199. X   case 1:
  200. X   case 5:
  201. X   /* Make a |    |----|    |----| type of line. */
  202. X      if ((1<<uPC_raster_count) & 0xF0F0) *(a) |= b;
  203. X      if (++uPC_raster_count > 15) uPC_raster_count = 0;
  204. X   break;
  205. X   case 2:
  206. X   case 6:
  207. X   /* Make a |----|----|----|--- |    | type of line. */
  208. X      if ((1<<uPC_raster_count) & 0x0EFFF) *(a) |= b;
  209. X      if (++uPC_raster_count > 19) uPC_raster_count = 0;
  210. X   break;
  211. X   case 3:
  212. X   case 7:
  213. X   /* Make a | -  | -  | -  | -  | type of line. */
  214. X      if ((1<<uPC_raster_count) & 0x4444) *(a) |= b;
  215. X      if (++uPC_raster_count > 15) uPC_raster_count = 0;
  216. X   break;
  217. X   case 4:
  218. X   case 8:
  219. X   default:
  220. X      *(a) |= b;
  221. X   break;
  222. X   }
  223. X}
  224. X
  225. XuPC_vector(x,y)
  226. Xunsigned int x,y;
  227. X{
  228. X/* This routine calls line with x,y */
  229. X   int x1 = uPC_sx, y1=uPC_sy, x2 = x, y2 = y;
  230. X   register int  c, e, dx, dy, width;
  231. X   register Scr_type mask, *a;
  232. X   static Scr_type lookup[] = {
  233. X      0x0001, 0x0002, 0x0004, 0x0008,
  234. X      0x0010, 0x0020, 0x0040, 0x0080,
  235. X      0x0100, 0x0200, 0x0400, 0x0800,
  236. X      0x1000, 0x2000, 0x4000, 0x8000,
  237. X   };
  238. X
  239. X/* Record new sx, sy for next call to the vector routine. */
  240. X   uPC_sx = x2;
  241. X   uPC_sy = y2;
  242. X
  243. X   a = &uPC_display[(uPC_YSIZE - 1) - y1][x1 >> 4];
  244. X   mask = lookup[x1 & 0x0f];
  245. X   width = uPC_width;
  246. X
  247. X   if ((dx = x2 - x1) > 0) {
  248. X      if ((dy = y2 - y1) > 0) {
  249. X         if (dx > dy) {         /* dx > 0, dy > 0, dx > dy */
  250. X            dy <<= 1;
  251. X            e = dy - dx;
  252. X            c = dx + 2;
  253. X            dx <<= 1;
  254. X
  255. X            while (--c) {
  256. X               uPC_PLOT(a, mask);
  257. X               if (e >= 0) {
  258. X                  (Scr_kluge *)a -= width;
  259. X                  e -= dx;
  260. X               }
  261. X               if (mask & uPC_HIGH_BIT) {
  262. X                  mask = 1;
  263. X                  a++;
  264. X               } else
  265. X                  mask <<= 1;
  266. X               e += dy;
  267. X            }
  268. X         } else {            /* dx > 0, dy > 0, dx <= dy */
  269. X            dx <<= 1;
  270. X            e = dx - dy;
  271. X            c = dy + 2;
  272. X            dy <<= 1;
  273. X
  274. X            while (--c) {
  275. X               uPC_PLOT(a, mask);
  276. X               if (e >= 0) {
  277. X                  if (mask & uPC_HIGH_BIT) {
  278. X                     mask = 1;
  279. X                     a++;
  280. X                  } else
  281. X                     mask <<= 1;
  282. X                  e -= dy;
  283. X               }
  284. X               (Scr_kluge *)a -= width;
  285. X               e += dx;
  286. X            }
  287. X         }
  288. X      } else {
  289. X         dy = -dy;
  290. X         if (dx > dy) {         /* dx > 0, dy <= 0, dx > dy */
  291. X            dy <<= 1;
  292. X            e = dy - dx;
  293. X            c = dx + 2;
  294. X            dx <<= 1;
  295. X
  296. X            while (--c) {
  297. X               uPC_PLOT(a, mask);
  298. X               if (e >= 0) {
  299. X                  (Scr_kluge *)a += width;
  300. X                  e -= dx;
  301. X               }
  302. X               if (mask & uPC_HIGH_BIT) {
  303. X                  mask = 1;
  304. X                  a++;
  305. X               } else
  306. X                  mask <<= 1;
  307. X               e += dy;
  308. X            }
  309. X         } else {            /* dx > 0, dy <= 0, dx <= dy */
  310. X            dx <<= 1;
  311. X            e = dx - dy;
  312. X            c = dy + 2;
  313. X            dy <<= 1;
  314. X
  315. X            while (--c) {
  316. X               uPC_PLOT(a, mask);
  317. X               if (e >= 0) {
  318. X                  if (mask & uPC_HIGH_BIT) {
  319. X                     mask = 1;
  320. X                     a++;
  321. X                  } else
  322. X                     mask <<= 1;
  323. X                  e -= dy;
  324. X               }
  325. X               (Scr_kluge *)a += width;
  326. X               e += dx;
  327. X            }
  328. X         }
  329. X      }
  330. X   } else {
  331. X      dx = -dx;
  332. X      if ((dy = y2 - y1) > 0) {
  333. X         if (dx > dy) {         /* dx <= 0, dy > 0, dx > dy */
  334. X            dy <<= 1;
  335. X            e = dy - dx;
  336. X            c = dx + 2;
  337. X            dx <<= 1;
  338. X
  339. X            while (--c) {
  340. X               uPC_PLOT(a, mask);
  341. X               if (e >= 0) {
  342. X                  (Scr_kluge *)a -= width;
  343. X                  e -= dx;
  344. X               }
  345. X               if (mask & 1) {
  346. X                  mask = uPC_HIGH_BIT;
  347. X                  a--;
  348. X               } else
  349. X                  mask >>= 1;
  350. X               e += dy;
  351. X            }
  352. X         } else {            /* dx <= 0, dy > 0, dx <= dy */
  353. X            dx <<= 1;
  354. X            e = dx - dy;
  355. X            c = dy + 2;
  356. X            dy <<= 1;
  357. X
  358. X            while (--c) {
  359. X               uPC_PLOT(a, mask);
  360. X               if (e >= 0) {
  361. X                  if (mask & 1) {
  362. X                     mask = uPC_HIGH_BIT;
  363. X                     a--;
  364. X                  } else
  365. X                     mask >>= 1;
  366. X                  e -= dy;
  367. X               }
  368. X               (Scr_kluge *)a -= width;
  369. X               e += dx;
  370. X            }
  371. X         }
  372. X      } else {
  373. X         dy = -dy;
  374. X         if (dx > dy) {         /* dx <= 0, dy <= 0, dx > dy */
  375. X            dy <<= 1;
  376. X            e = dy - dx;
  377. X            c = dx + 2;
  378. X            dx <<= 1;
  379. X
  380. X            while (--c) {
  381. X               uPC_PLOT(a, mask);
  382. X               if (e >= 0) {
  383. X                  (Scr_kluge *)a += width;
  384. X                  e -= dx;
  385. X               }
  386. X               if (mask & 1) {
  387. X                  mask = uPC_HIGH_BIT;
  388. X                  a--;
  389. X               } else
  390. X                  mask >>= 1;
  391. X               e += dy;
  392. X            }
  393. X         } else {            /* dx <= 0, dy <= 0, dx <= dy */
  394. X            dx <<= 1;
  395. X            e = dx - dy;
  396. X            c = dy + 2;
  397. X            dy <<= 1;
  398. X
  399. X            while (--c) {
  400. X               uPC_PLOT(a, mask);
  401. X               if (e >= 0) {
  402. X                  if (mask & 1) {
  403. X                     mask = uPC_HIGH_BIT;
  404. X                     a--;
  405. X                  } else
  406. X                     mask >>= 1;
  407. X                  e -= dy;
  408. X               }
  409. X               (Scr_kluge *)a += width;
  410. X               e += dx;
  411. X            }
  412. X         }
  413. X      }
  414. X   }
  415. X}
  416. X
  417. X
  418. XuPC_lrput_text(row,str)
  419. Xunsigned int row;
  420. Xchar str[];
  421. X{
  422. X   int col = 80-strlen(str), num, i;
  423. X   struct utdata ut;
  424. X   char *txt=ut.ut_text;
  425. X
  426. X/* Fill in the pad. */
  427. X   for (i = 0; i < col; i++)
  428. X      txt[i] = ' ';
  429. X/* Then stick in the text. */
  430. X   txt[i] = '\0';
  431. X   strcat (txt, str);
  432. X
  433. X   if (row > 2)
  434. X      puts (txt);
  435. X   else {
  436. X   /* This will fit on the 2 bottom "non-graphic" lines. */
  437. X      switch (row) {
  438. X      case 0: ut.ut_num =  WTXTSLK1; break;
  439. X      case 1: ut.ut_num =  WTXTSLK2; break;
  440. X      }
  441. X      ioctl (0, WIOCSETTEXT, &ut);
  442. X   }
  443. X   wgoto (1, 24, 0);
  444. X}
  445. X
  446. XuPC_ulput_text(row,str)
  447. Xunsigned int row;
  448. Xchar str[];
  449. X{
  450. X/* This routine puts the text in the upper left corner. */
  451. X
  452. X/* Just use the ANSI escape sequence CUP (iswind said that was ok!) */
  453. X   printf ("\033[%d;%dH%s\033[25;1H", row+2, 2, str); /* +1 +2 ? */
  454. X   fflush (stdout);
  455. X}
  456. X
  457. X
  458. XuPC_reset()
  459. X{
  460. X/* Reset window to normal size. */
  461. X   uPC_fixwind (0);
  462. X}
  463. X
  464. X
  465. X
  466. XuPC_fixwind(signo)
  467. Xint signo;
  468. X{
  469. X   static struct uwdata wreset = { 0, 12, 720, 288, 0x1};
  470. X   struct utdata ut;
  471. X
  472. X/* Reset the window to the right size. */
  473. X   ioctl(0, WIOCSETD, &wreset);   /* 0, not wncur here! */
  474. X
  475. X/* Clear the lines affected by an _lrput_text. */
  476. X   ut.ut_text[0] = '\0';
  477. X   ut.ut_num =  WTXTSLK1;
  478. X   ioctl(0, WIOCSETTEXT, &ut);
  479. X   ut.ut_num =  WTXTSLK2;
  480. X   ioctl(0, WIOCSETTEXT, &ut);
  481. X/* Scroll the screen once. (avoids typing over the same line) */
  482. X   fprintf (stderr, "\n");
  483. X
  484. X   if (signo) {
  485. X      if (signo == SIGILL || signo == SIGTRAP || signo == SIGPWR)
  486. X         signal (signo, SIG_DFL);
  487. X      kill (0,signo);  /* Redo the signal (as if we never trapped it). */
  488. X   }
  489. X}
  490. END_OF_FILE
  491. if test 12181 -ne `wc -c <'unixpc.trm'`; then
  492.     echo shar: \"'unixpc.trm'\" unpacked with wrong size!
  493. fi
  494. # end of 'unixpc.trm'
  495. fi
  496. if test -f 'unixplot.trm' -a "${1}" != "-c" ; then 
  497.   echo shar: Will not clobber existing file \"'unixplot.trm'\"
  498. else
  499. echo shar: Extracting \"'unixplot.trm'\" \(998 characters\)
  500. sed "s/^X//" >'unixplot.trm' <<'END_OF_FILE'
  501. X#define UP_XMAX 4096
  502. X#define UP_YMAX 4096
  503. X
  504. X#define UP_XLAST (UP_XMAX - 1)
  505. X#define UP_YLAST (UP_YMAX - 1)
  506. X
  507. X#define UP_VCHAR (UP_YMAX/30)
  508. X#define UP_HCHAR (UP_XMAX/72)    /* just a guess--no way to know this! */
  509. X#define UP_VTIC (UP_YMAX/80)
  510. X#define UP_HTIC (UP_XMAX/80)
  511. X
  512. XUP_init()
  513. X{
  514. X    openpl();
  515. X    space(0, 0, UP_XMAX, UP_YMAX);
  516. X}
  517. X
  518. X
  519. XUP_graphics()
  520. X{
  521. X    erase();
  522. X}
  523. X
  524. X
  525. XUP_text()
  526. X{
  527. X}
  528. X
  529. X
  530. XUP_linetype(linetype)
  531. Xint linetype;
  532. X{
  533. Xstatic char *lt[2+5] = {"solid", "longdashed", "solid", "dotted","shortdashed",
  534. X    "dotdashed", "longdashed"};
  535. X
  536. X    if (linetype >= 5)
  537. X        linetype %= 5;
  538. X    linemod(lt[linetype+2]);
  539. X}
  540. X
  541. X
  542. XUP_move(x,y)
  543. Xunsigned int x,y;
  544. X{
  545. X    move(x,y);
  546. X}
  547. X
  548. X
  549. XUP_vector(x,y)
  550. Xunsigned int x,y;
  551. X{
  552. X    cont(x,y);
  553. X}
  554. X
  555. X
  556. XUP_lrput_text(row,str)
  557. Xunsigned int row;
  558. Xchar str[];
  559. X{
  560. X    move(UP_XMAX - UP_HTIC - UP_HCHAR*(strlen(str)+1),
  561. X        UP_VTIC + UP_VCHAR*(row+1));
  562. X    label(str);
  563. X}
  564. X
  565. X
  566. XUP_ulput_text(row,str)
  567. Xunsigned int row;
  568. Xchar str[];
  569. X{
  570. X    UP_move(UP_HTIC, UP_YMAX - UP_VTIC - UP_VCHAR*(row+1));
  571. X    label(str);
  572. X}
  573. X
  574. XUP_reset()
  575. X{
  576. X    closepl();
  577. X}
  578. X
  579. X
  580. END_OF_FILE
  581. if test 998 -ne `wc -c <'unixplot.trm'`; then
  582.     echo shar: \"'unixplot.trm'\" unpacked with wrong size!
  583. fi
  584. # end of 'unixplot.trm'
  585. fi
  586. if test -f 'util.c' -a "${1}" != "-c" ; then 
  587.   echo shar: Will not clobber existing file \"'util.c'\"
  588. else
  589. echo shar: Extracting \"'util.c'\" \(8430 characters\)
  590. sed "s/^X//" >'util.c' <<'END_OF_FILE'
  591. X/*
  592. X *
  593. X *    G N U P L O T  --  util.c
  594. X *
  595. X *  Copyright (C) 1986, 1987  Thomas Williams, Colin Kelley
  596. X *
  597. X *  You may use this code as you wish if credit is given and this message
  598. X *  is retained.
  599. X *
  600. X *  Please e-mail any useful additions to vu-vlsi!plot so they may be
  601. X *  included in later releases.
  602. X *
  603. X *  This file should be edited with 4-column tabs!  (:set ts=4 sw=4 in vi)
  604. X */
  605. X
  606. X#include <ctype.h>
  607. X#include <setjmp.h>
  608. X#include <stdio.h>
  609. X#include <errno.h>
  610. X#include "plot.h"
  611. X
  612. Xextern BOOLEAN screen_ok;
  613. X    /* TRUE if command just typed; becomes FALSE whenever we
  614. X        send some other output to screen.  If FALSE, the command line
  615. X        will be echoed to the screen before the ^ error message. */
  616. X
  617. Xchar *malloc();
  618. X
  619. X#ifndef vms
  620. Xextern int errno, sys_nerr;
  621. Xextern char *sys_errlist[];
  622. X#endif /* vms */
  623. X
  624. Xextern char input_line[];
  625. Xextern struct lexical_unit token[];
  626. Xextern jmp_buf env;    /* from plot.c */
  627. X
  628. X
  629. X/*
  630. X * equals() compares string value of token number t_num with str[], and
  631. X *   returns TRUE if they are identical.
  632. X */
  633. Xequals(t_num, str)
  634. Xint t_num;
  635. Xchar *str;
  636. X{
  637. Xregister int i;
  638. X
  639. X    if (!token[t_num].is_token)
  640. X        return(FALSE);                /* must be a value--can't be equal */
  641. X    for (i = 0; i < token[t_num].length; i++) {
  642. X        if (input_line[token[t_num].start_index+i] != str[i])
  643. X            return(FALSE);
  644. X        }
  645. X    /* now return TRUE if at end of str[], FALSE if not */
  646. X    return(str[i] == '\0');
  647. X}
  648. X
  649. X
  650. X
  651. X/*
  652. X * almost_equals() compares string value of token number t_num with str[], and
  653. X *   returns TRUE if they are identical up to the first $ in str[].
  654. X */
  655. Xalmost_equals(t_num, str)
  656. Xint t_num;
  657. Xchar *str;
  658. X{
  659. Xregister int i;
  660. Xregister int after = 0;
  661. Xregister start = token[t_num].start_index;
  662. Xregister length = token[t_num].length;
  663. X
  664. X    if (!token[t_num].is_token)
  665. X        return(FALSE);                /* must be a value--can't be equal */
  666. X    for (i = 0; i < length + after; i++) {
  667. X        if (str[i] != input_line[start + i]) {
  668. X            if (str[i] != '$')
  669. X                return(FALSE);
  670. X            else {
  671. X                after = 1;
  672. X                start--;    /* back up token ptr */
  673. X                }
  674. X            }
  675. X        }
  676. X
  677. X    /* i now beyond end of token string */
  678. X
  679. X    return(after || str[i] == '$' || str[i] == '\0');
  680. X}
  681. X
  682. X
  683. X
  684. Xisstring(t_num)
  685. Xint t_num;
  686. X{
  687. X    
  688. X    return(token[t_num].is_token &&
  689. X           (input_line[token[t_num].start_index] == '\'' ||
  690. X           input_line[token[t_num].start_index] == '\"'));
  691. X}
  692. X
  693. X
  694. Xisnumber(t_num)
  695. Xint t_num;
  696. X{
  697. X    return(!token[t_num].is_token);
  698. X}
  699. X
  700. X
  701. Xisletter(t_num)
  702. Xint t_num;
  703. X{
  704. X    return(token[t_num].is_token &&
  705. X            (isalpha(input_line[token[t_num].start_index])));
  706. X}
  707. X
  708. X
  709. X/*
  710. X * is_definition() returns TRUE if the next tokens are of the form
  711. X *   identifier =
  712. X *        -or-
  713. X *   identifier ( identifer ) =
  714. X */
  715. Xis_definition(t_num)
  716. Xint t_num;
  717. X{
  718. X    return (isletter(t_num) &&
  719. X            (equals(t_num+1,"=") ||            /* variable */
  720. X            (equals(t_num+1,"(") &&        /* function */
  721. X             isletter(t_num+2)   &&
  722. X             equals(t_num+3,")") &&
  723. X             equals(t_num+4,"=") )
  724. X        ));
  725. X}
  726. X
  727. X
  728. X
  729. X/*
  730. X * copy_str() copies the string in token number t_num into str, appending
  731. X *   a null.  No more than MAX_ID_LEN chars are copied.
  732. X */
  733. Xcopy_str(str, t_num)
  734. Xchar str[];
  735. Xint t_num;
  736. X{
  737. Xregister int i = 0;
  738. Xregister int start = token[t_num].start_index;
  739. Xregister int count;
  740. X
  741. X    if ((count = token[t_num].length) > MAX_ID_LEN)
  742. X        count = MAX_ID_LEN;
  743. X    do {
  744. X        str[i++] = input_line[start++];
  745. X        } while (i != count);
  746. X    str[i] = '\0';
  747. X}
  748. X
  749. X
  750. X/*
  751. X * quote_str() does the same thing as copy_str, except it ignores the
  752. X *   quotes at both ends.  This seems redundant, but is done for
  753. X *   efficency.
  754. X */
  755. Xquote_str(str, t_num)
  756. Xchar str[];
  757. Xint t_num;
  758. X{
  759. Xregister int i = 0;
  760. Xregister int start = token[t_num].start_index + 1;
  761. Xregister int count;
  762. X
  763. X    if ((count = token[t_num].length - 2) > MAX_ID_LEN)
  764. X        count = MAX_ID_LEN;
  765. X    do {
  766. X        str[i++] = input_line[start++];
  767. X        } while (i != count);
  768. X    str[i] = '\0';
  769. X}
  770. X
  771. X
  772. X/*
  773. X *    capture() copies into str[] the part of input_line[] which lies between
  774. X *    the begining of token[start] and end of token[end].
  775. X */
  776. Xcapture(str,start,end)
  777. Xchar str[];
  778. Xint start,end;
  779. X{
  780. Xregister int i,e;
  781. X
  782. X    e = token[end].start_index + token[end].length;
  783. X    for (i = token[start].start_index; i < e && input_line[i] != '\0'; i++)
  784. X        *str++ = input_line[i];
  785. X    *str = '\0';
  786. X}
  787. X
  788. X
  789. X/*
  790. X *    m_capture() is similar to capture(), but it mallocs storage for the
  791. X *  string.
  792. X */
  793. Xm_capture(str,start,end)
  794. Xchar **str;
  795. Xint start,end;
  796. X{
  797. Xregister int i,e;
  798. Xregister char *s;
  799. X
  800. X    if (*str)        /* previous pointer to malloc'd memory there */
  801. X        free(*str);
  802. X    e = token[end].start_index + token[end].length;
  803. X    if (*str = malloc((unsigned int)(e - token[start].start_index + 1))) {
  804. X        s = *str;
  805. X        for (i = token[start].start_index; i < e && input_line[i] != '\0'; i++)
  806. X            *s++ = input_line[i];
  807. X        *s = '\0';
  808. X    }
  809. X}
  810. X
  811. X
  812. Xconvert(val_ptr, t_num)
  813. Xstruct value *val_ptr;
  814. Xint t_num;
  815. X{
  816. X    *val_ptr = token[t_num].l_val;
  817. X}
  818. X
  819. X
  820. X
  821. Xdisp_value(fp,val)
  822. XFILE *fp;
  823. Xstruct value *val;
  824. X{
  825. X        switch(val->type) {
  826. X            case INT:
  827. X                fprintf(fp,"%d",val->v.int_val);
  828. X                break;
  829. X            case CMPLX:
  830. X                if (val->v.cmplx_val.imag != 0.0 )
  831. X                    fprintf(fp,"{%g, %g}",
  832. X                        val->v.cmplx_val.real,val->v.cmplx_val.imag);
  833. X                else
  834. X                    fprintf(fp,"%g", val->v.cmplx_val.real);
  835. X                break;
  836. X            default:
  837. X                int_error("unknown type in disp_value()",NO_CARET);
  838. X        }
  839. X}
  840. X
  841. X
  842. Xdouble
  843. Xreal(val)        /* returns the real part of val */
  844. Xstruct value *val;
  845. X{
  846. X    switch(val->type) {
  847. X        case INT:
  848. X            return((double) val->v.int_val);
  849. X            break;
  850. X        case CMPLX:
  851. X            return(val->v.cmplx_val.real);
  852. X    }
  853. X    int_error("unknown type in real()",NO_CARET);
  854. X    /* NOTREACHED */
  855. X}
  856. X
  857. X
  858. Xdouble
  859. Ximag(val)        /* returns the imag part of val */
  860. Xstruct value *val;
  861. X{
  862. X    switch(val->type) {
  863. X        case INT:
  864. X            return(0.0);
  865. X            break;
  866. X        case CMPLX:
  867. X            return(val->v.cmplx_val.imag);
  868. X    }
  869. X    int_error("unknown type in real()",NO_CARET);
  870. X    /* NOTREACHED */
  871. X}
  872. X
  873. X
  874. X
  875. Xdouble
  876. Xmagnitude(val)        /* returns the magnitude of val */
  877. Xstruct value *val;
  878. X{
  879. X    double sqrt();
  880. X
  881. X    switch(val->type) {
  882. X        case INT:
  883. X            return((double) abs(val->v.int_val));
  884. X            break;
  885. X        case CMPLX:
  886. X            return(sqrt(val->v.cmplx_val.real*
  887. X                    val->v.cmplx_val.real +
  888. X                    val->v.cmplx_val.imag*
  889. X                    val->v.cmplx_val.imag));
  890. X    }
  891. X    int_error("unknown type in magnitude()",NO_CARET);
  892. X    /* NOTREACHED */
  893. X}
  894. X
  895. X
  896. X
  897. Xdouble
  898. Xangle(val)        /* returns the angle of val */
  899. Xstruct value *val;
  900. X{
  901. X    double atan2();
  902. X
  903. X    switch(val->type) {
  904. X        case INT:
  905. X            return((val->v.int_val > 0) ? 0.0 : Pi);
  906. X            break;
  907. X        case CMPLX:
  908. X            if (val->v.cmplx_val.imag == 0.0) {
  909. X                if (val->v.cmplx_val.real >= 0.0)
  910. X                    return(0.0);
  911. X                else
  912. X                    return(Pi);
  913. X            }
  914. X            return(atan2(val->v.cmplx_val.imag,
  915. X                     val->v.cmplx_val.real));
  916. X    }
  917. X    int_error("unknown type in angle()",NO_CARET);
  918. X    /* NOTREACHED */
  919. X}
  920. X
  921. X
  922. Xstruct value *
  923. Xcomplex(a,realpart,imagpart)
  924. Xstruct value *a;
  925. Xdouble realpart, imagpart;
  926. X{
  927. X    a->type = CMPLX;
  928. X    a->v.cmplx_val.real = realpart;
  929. X    a->v.cmplx_val.imag = imagpart;
  930. X    return(a);
  931. X}
  932. X
  933. X
  934. Xstruct value *
  935. Xinteger(a,i)
  936. Xstruct value *a;
  937. Xint i;
  938. X{
  939. X    a->type = INT;
  940. X    a->v.int_val = i;
  941. X    return(a);
  942. X}
  943. X
  944. X
  945. X
  946. Xos_error(str,t_num)
  947. Xchar str[];
  948. Xint t_num;
  949. X{
  950. X#ifdef vms
  951. Xstatic status[2] = {1, 0};        /* 1 is count of error msgs */
  952. X#endif
  953. X
  954. Xregister int i;
  955. X
  956. X    /* reprint line if screen has been written to */
  957. X
  958. X    if (t_num != NO_CARET) {        /* put caret under error */
  959. X        if (!screen_ok)
  960. X            fprintf(stderr,"\n%s%s\n", PROMPT, input_line);
  961. X
  962. X        for (i = 0; i < sizeof(PROMPT) - 1; i++)
  963. X            (void) putc(' ',stderr);
  964. X        for (i = 0; i < token[t_num].start_index; i++) {
  965. X            (void) putc((input_line[i] == '\t') ? '\t' : ' ',stderr);
  966. X            }
  967. X        (void) putc('^',stderr);
  968. X        (void) putc('\n',stderr);
  969. X    }
  970. X
  971. X    for (i = 0; i < sizeof(PROMPT) - 1; i++)
  972. X        (void) putc(' ',stderr);
  973. X    fprintf(stderr,"%s\n",str);
  974. X
  975. X    for (i = 0; i < sizeof(PROMPT) - 1; i++)
  976. X        (void) putc(' ',stderr);
  977. X#ifdef vms
  978. X    status[1] = vaxc$errno;
  979. X    sys$putmsg(status);
  980. X    (void) putc('\n',stderr);
  981. X#else
  982. X    if (errno >= sys_nerr)
  983. X        fprintf(stderr, "unknown errno %d\n\n", errno);
  984. X    else
  985. X        fprintf(stderr,"(%s)\n\n",sys_errlist[errno]);
  986. X#endif
  987. X
  988. X    longjmp(env, TRUE);    /* bail out to command line */
  989. X}
  990. X
  991. X
  992. Xint_error(str,t_num)
  993. Xchar str[];
  994. Xint t_num;
  995. X{
  996. Xregister int i;
  997. X
  998. X    /* reprint line if screen has been written to */
  999. X
  1000. X    if (t_num != NO_CARET) {        /* put caret under error */
  1001. X        if (!screen_ok)
  1002. X            fprintf(stderr,"\n%s%s\n", PROMPT, input_line);
  1003. X
  1004. X        for (i = 0; i < sizeof(PROMPT) - 1; i++)
  1005. X            (void) putc(' ',stderr);
  1006. X        for (i = 0; i < token[t_num].start_index; i++) {
  1007. X            (void) putc((input_line[i] == '\t') ? '\t' : ' ',stderr);
  1008. X            }
  1009. X        (void) putc('^',stderr);
  1010. X        (void) putc('\n',stderr);
  1011. X    }
  1012. X
  1013. X    for (i = 0; i < sizeof(PROMPT) - 1; i++)
  1014. X        (void) putc(' ',stderr);
  1015. X    fprintf(stderr,"%s\n\n",str);
  1016. X
  1017. X    longjmp(env, TRUE);    /* bail out to command line */
  1018. X}
  1019. END_OF_FILE
  1020. if test 8430 -ne `wc -c <'util.c'`; then
  1021.     echo shar: \"'util.c'\" unpacked with wrong size!
  1022. fi
  1023. # end of 'util.c'
  1024. fi
  1025. if test -f 'v384.trm' -a "${1}" != "-c" ; then 
  1026.   echo shar: Will not clobber existing file \"'v384.trm'\"
  1027. else
  1028. echo shar: Extracting \"'v384.trm'\" \(1966 characters\)
  1029. sed "s/^X//" >'v384.trm' <<'END_OF_FILE'
  1030. X/*
  1031. X *  thanks to roland@moncskermit.OZ (Roland Yap) for this driver
  1032. X *
  1033. X *    Vectrix 384 driver - works with tandy color printer as well
  1034. X *  in reverse printing 8 color mode.
  1035. X *  This doesn't work on Vectrix 128 because it redefines the
  1036. X *  color table. It can be hacked to work on the 128 by changing
  1037. X *  the colours but then it will probably not print best. The color
  1038. X *  table is purposely designed so that it will print well
  1039. X *
  1040. X */
  1041. X
  1042. X#define V384_XMAX 630
  1043. X#define V384_YMAX 480
  1044. X
  1045. X#define V384_XLAST (V384_XMAX - 1)
  1046. X#define V384_YLAST (V384_YMAX - 1)
  1047. X
  1048. X#define V384_VCHAR    12
  1049. X#define V384_HCHAR    7
  1050. X#define V384_VTIC    8
  1051. X#define V384_HTIC    7
  1052. X
  1053. X
  1054. XV384_init()
  1055. X{
  1056. X    fprintf(outfile,"%c%c  G0   \n",27,18);
  1057. X    fprintf(outfile,"Q 0 8\n");
  1058. X    fprintf(outfile,"0 0 0\n");
  1059. X    fprintf(outfile,"255 0 0\n");
  1060. X    fprintf(outfile,"0 255 0\n");
  1061. X    fprintf(outfile,"0 0 255\n");
  1062. X    fprintf(outfile,"0 255 255\n");
  1063. X    fprintf(outfile,"255 0 255\n");
  1064. X    fprintf(outfile,"255 255 0\n");
  1065. X    fprintf(outfile,"255 255 255\n");
  1066. X}
  1067. X
  1068. X
  1069. XV384_graphics()
  1070. X{
  1071. X    fprintf(outfile,"%c%c E0 RE N 65535\n",27,18);
  1072. X}
  1073. X
  1074. X
  1075. XV384_text()
  1076. X{
  1077. X    fprintf(outfile,"%c%c\n",27,17);
  1078. X}
  1079. X
  1080. X
  1081. XV384_linetype(linetype)
  1082. Xint linetype;
  1083. X{
  1084. Xstatic int color[]= {
  1085. X        1 /* red */,
  1086. X        2 /* green */,
  1087. X        3 /* blue */,
  1088. X        4 /* cyan */,
  1089. X        5 /* magenta */,
  1090. X        6 /* yellow */, /* not a good color so not in use at the moment */
  1091. X        7 /* white */
  1092. X    };
  1093. X        
  1094. X    if (linetype < 0)
  1095. X        linetype=6;
  1096. X    else
  1097. X        linetype %= 5;
  1098. X    fprintf(outfile,"C %d\n",color[linetype]);
  1099. X}
  1100. X
  1101. X
  1102. XV384_move(x,y)
  1103. Xunsigned int x,y;
  1104. X{
  1105. X    fprintf(outfile,"M %d %d\n",x+20,y);
  1106. X}
  1107. X
  1108. X
  1109. XV384_vector(x,y)
  1110. Xunsigned int x,y;
  1111. X{
  1112. X    fprintf(outfile,"L %d %d\n",x+20,y);
  1113. X}
  1114. X
  1115. X
  1116. XV384_lrput_text(row,str)
  1117. Xunsigned int row;
  1118. Xchar str[];
  1119. X{
  1120. X    V384_move(V384_XMAX - V384_HTIC - V384_HCHAR*(strlen(str)+1),
  1121. X        V384_VTIC + V384_VCHAR*(row+1));
  1122. X    fprintf(outfile,"$%s\n",str);
  1123. X}
  1124. X
  1125. X
  1126. XV384_ulput_text(row,str)
  1127. Xunsigned int row;
  1128. Xchar str[];
  1129. X{
  1130. X    V384_move(V384_HTIC, V384_YMAX - V384_VTIC - V384_VCHAR*(row+1));
  1131. X    fprintf(outfile,"$%s\n",str);
  1132. X}
  1133. X
  1134. X
  1135. XV384_reset()
  1136. X{
  1137. X}
  1138. X
  1139. X
  1140. END_OF_FILE
  1141. if test 1966 -ne `wc -c <'v384.trm'`; then
  1142.     echo shar: \"'v384.trm'\" unpacked with wrong size!
  1143. fi
  1144. # end of 'v384.trm'
  1145. fi
  1146. if test -f 'version.c' -a "${1}" != "-c" ; then 
  1147.   echo shar: Will not clobber existing file \"'version.c'\"
  1148. else
  1149. echo shar: Extracting \"'version.c'\" \(1467 characters\)
  1150. sed "s/^X//" >'version.c' <<'END_OF_FILE'
  1151. X/*
  1152. X *  Modified version of 1.1.0 gnuplot by Thomas Williams and Colin Kelley.
  1153. X *  "You may use this code as you wish if credit is given and this message
  1154. X *  is retained."
  1155. X *
  1156. X *  Our "use" of this code has been to add a terminal driver (att 3b1),
  1157. X *  improve the IBM-PC drivers using TURBO-C routines, throw in a
  1158. X *  different help system (the one we got didn't seem to work) and add
  1159. X *  the commands SET POLAR, SET OFFSETS, and PAUSE.
  1160. X *
  1161. X *  Files that were changed from the original 1.1.0 version:
  1162. X *  command.c, graphics.c, misc.c, plot.c, term.c and version.c.
  1163. X *
  1164. X *  The annoying problem with unixplot files not being redirected by
  1165. X *  the set output command was fixed and an ``init()'' routine was
  1166. X *  added to term.c to allow an implementation to detect the terminal
  1167. X *  type.  (Currently only used by TURBO-C and VMS.)  The file term.c
  1168. X *  was further changed by breaking it into a number of .TRM files
  1169. X *  (Makefile was changed accordingly).
  1170. X *
  1171. X *  A bug in do_plot() was fixed as well as a VMS bug that caused
  1172. X *  SET OUTPUT to fail.  A final departure from the original 1.1.0
  1173. X *  version was the addition of Jyrki Yli-Nokari's HP laser jet
  1174. X *  drivers to term.c.
  1175. X *
  1176. X *  John Campbell  CAMPBELL@NAUVAX.bitnet (3b1, polar, offsets, pause)
  1177. X *  Bill Wilson    WILSON@NAUVAX.bitnet   (TURBO-C IBM-PC drivers)
  1178. X *  Steve Wampler  ...!arizona!naucse!sbw (help system acquisition)
  1179. X */
  1180. Xchar version[] = "1.1.0A (Polar)";
  1181. Xchar date[] = "Thu May 18 21:57:24 MST 1989";
  1182. END_OF_FILE
  1183. if test 1467 -ne `wc -c <'version.c'`; then
  1184.     echo shar: \"'version.c'\" unpacked with wrong size!
  1185. fi
  1186. # end of 'version.c'
  1187. fi
  1188. echo shar: End of archive 5 \(of 7\).
  1189. cp /dev/null ark5isdone
  1190. MISSING=""
  1191. for I in 1 2 3 4 5 6 7 ; do
  1192.     if test ! -f ark${I}isdone ; then
  1193.     MISSING="${MISSING} ${I}"
  1194.     fi
  1195. done
  1196. if test "${MISSING}" = "" ; then
  1197.     echo You have unpacked all 7 archives.
  1198.     rm -f ark[1-9]isdone
  1199. else
  1200.     echo You still need to unpack the following archives:
  1201.     echo "        " ${MISSING}
  1202. fi
  1203. ##  End of shell archive.
  1204. exit 0
  1205.